package view.pane;

import controller.human.Person;
import controller.human.User;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import view.Gui;

@SuppressWarnings("serial")
public class RootPane extends JPanel {
	Gui gui;
	public RootPane(Gui guiParam) {
		this.gui = guiParam;
		
		final JTextField adminName = new JTextField("admin", 10);
		final JPasswordField adminPassword = new JPasswordField("pass", 10);
		
		JButton helpButton = new JButton("Help");
		JButton gameButton = new JButton("New Game");
		
		gameButton.addActionListener( 
			new ActionListener() {
                                @Override
				public void actionPerformed(ActionEvent e) {
					gui.setAdmin(adminName.getText(), (adminPassword.getPassword().toString()));
                                        User u = Person.getUser(adminName.getText());
                                        u.setPassword(adminPassword.getPassword().toString());
                                        gui.addUser(u);
					gui.updatePane(new ConfigurationPane(gui));
				}
			}
		);
		
		this.add(adminName); this.add(adminPassword);
		this.add(helpButton);
		this.add(gameButton);
	}
}
